<?php
	class Login {
		function cekLogin($user, $pass) {
			$user = addslashes($user);
			$pass = addslashes($pass);
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select * from user where userName = '$user' and userStatus = 1";
			
			if($mysql->execute($query)) {
				$dataLogin = $mysql->getDataSet();
				if(empty($dataLogin)){
					return false;
				} else {
					if($dataLogin[0][2] == $pass) {
						session_start();
						$_SESSION['userId'] = $dataLogin[0][0];
						return true;
					} else {
						return false;
					}
				}
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function editLogin($userId, $user, $pass){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "update user set userName = $user, userPassword = $pass where userId = $userId" ;
			if($mysql->execute($query)) {
				return true;
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function addLogin($user, $pass, $email){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "insert into user (userName, userPassword, userStatus, userMail) values('$user', '$pass',1,'$email')";
			if($mysql->execute($query)) {
				return true;
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function delLogin($userId) {
			$mysql = new Mysql();
			$mysql->connect();
			$query = "delete user where userId = $userId";
			if($mysql->execute($query)) {
				return true;
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
	}
	
?>